package com.mall.user.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mall.user.model.Areas;
import com.mall.common.util.RespResult;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mall.user.service.IAreasService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


/**
 * <p>
 * 区域表 控制器
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "REST - 区域表")
@RestController
@RequestMapping("/areas")
public class AreasController {
    private final IAreasService service;

    @PostMapping("/addAreas")
    @ApiOperation(value = "新增")
    public RespResult addAreas(@RequestBody Areas areas){
        boolean flag = service.addAreas(areas);
        return RespResult.ok(flag ? "创建成功" : "创建失败");
    }

    @DeleteMapping("/delete/{areaid}")
    @ApiOperation(value = "根据id删除")
    public RespResult deleteById(@PathVariable("areaid") String areaid){
        boolean flag = service.deleteById(areaid);
        return RespResult.ok(flag ? "删除成功" : "删除失败");
    }

    @PutMapping("/updateAreas")
    @ApiOperation(value = "更新")
    public RespResult updateAreas(@RequestBody Areas areas){
        boolean flag = service.updateAreas(areas);
        return RespResult.ok(flag ? "更新成功" : "更新失败");
    }

    @GetMapping("/{areaid}")
    @ApiOperation(value = "根据id查询")
    public RespResult getById(@PathVariable("areaid") String areaid){
        return RespResult.ok(service.getById(areaid));
    }

    @PostMapping("/selectList")
    @ApiOperation(value = "根据条件查询全部数据")
    public RespResult selectList(Areas areas){
        return RespResult.ok(service.selectList(areas));
    }

    @PostMapping("/selectPage")
    @ApiOperation(value = "分页查询")
    public RespResult selectPage(Page<Areas> page, Areas areas){
        return RespResult.ok(service.selectPage(page, areas));
    }

}